<?php

namespace App\Admin\Controller\Application;


use App\Admin\Controller\AdminBaseController;
use App\Admin\Requests\Application\Application\ApplicationStoreRequest;
use App\Admin\Requests\Application\Application\ApplicationUpdateRequest;
use App\Admin\Services\Application\ApplicationService;

class ApplicationController extends AdminBaseController {
    /**
     * @param ApplicationService $service
     * @return mixed
     */
    public function page(ApplicationService $service) {
        return $this->success($service->applicationPage());
    }
    
    /**
     * @param ApplicationStoreRequest $request
     * @param ApplicationService      $service
     * @return mixed
     */
    public function store(ApplicationStoreRequest $request, ApplicationService $service) {
        return $this->success($service->applicationStore(
            $request->input(),
            $request->getRuleKeys()
        ));
    }
    
    /**
     * @param ApplicationUpdateRequest $request
     * @param ApplicationService       $service
     * @param                          $id
     * @return mixed
     * @throws \Exception
     */
    public function update(ApplicationUpdateRequest $request, ApplicationService $service, $id) {
        return $this->success($service->applicationUpdate(
            $id,
            $request->input(),
            $request->getRuleKeys()
        ));
    }
    
    /**
     * @param ApplicationService $service
     * @param                    $id
     * @return mixed
     * @throws \Exception
     */
    public function destroy(ApplicationService $service, $id) {
        return $this->success($service->applicationDestroy($id));
    }
    
    /**
     * 更新应用秘钥
     *
     * @param ApplicationService $service
     * @param                    $id
     *
     * @return mixed
     * @throws \Exception
     */
    public function updateSecretKey(ApplicationService $service, $id) {
        return $this->success($service->applicationUpdateSecretKey($id));
    }
}